// type TwoDimensionCfg = typeof ModelMapConfig["EL-DJ"];

//ES6 Generator 函数, 为不具备 Iterator 接口的对象提供遍历方法。   https://www.runoob.com/w3cnote/es6-generator.html
function* entries(obj :any) {
    //const propKeys = Reflect.ownKeys(obj);返回对象所有的属性，不管属性是否可枚举，包括 Symbol。
    for (let key of Object.keys(obj)) {
        yield [key, obj[key]];
    }
}

/**根据设备类别和业务类型性质来搜索可能使用的报告模板类型的列表。
 * 输出有顺序的：匹配最佳的放在[0]第一位上。
 * */
export function getReportModelTypes(
    sort: string,vart: string,subvart: string,bsType: string,entrust:boolean
): string []
{
    let mac2bind=[] as  [string,number][];     //前面放入报告模板编号，后面放入匹配程度等级；
    /*for (var key of Object.keys(someObject)) {
        console.log(key + ': ' + someObject[key]);
      }   */
    let m=0;
    //是否满足，最大的满足程度 0，1，，，，4个条件都满足的。  ==0不满足删除。
    for (let [key, value] of entries(ModelMapConfig)) {
        let matched=0;      //配对等级 程度好的
        for (const gz of value) {         //value[ [], ]可以用这个模板的条件，多个 gz1 or gz2 or ...
            if(null!==gz[3]){
                if(typeof gz[3]==='string'){
                    if(gz[3]!==bsType)   continue;
                }else{
                    //数组形式的配置【多选的 业务类型】
                    if(! gz[3].find((it:any) => it === bsType) )
                        continue;
                }
            }                   //业务类别提前做的排除：
            if(null===gz[4] || (false===gz[4] && !entrust) || (true===gz[4] && entrust) ) {
                //剩下就是设备分类的匹配
                if (!gz[0]) {         //任意vart的设备？最宽松条件了；
                    if (matched <= 0)   matched = 1;
                    continue;
                } else if (gz[0] === sort) {
                    if (!gz[1]) {         //任意sort的设备
                        if (matched <= 1)   matched = 2;
                        continue;
                    }else if (gz[1] === vart) {
                        if (!gz[2]) {         //任意subvart的设备
                            if (matched <= 2)   matched = 3;
                            continue;
                        }else if (gz[2] === subvart) {
                            matched = 4;
                        }
                    }
                }
            }
            if(matched>= 4)     break;      //最高可能的等级
        }
        if(matched>0)
            mac2bind[m++] = [key, matched];
    }
    //必须interface Array<T> 才能用的sort()操作
    mac2bind.sort(function(a, b) {
        if (a[1] > b[1]) {        //比较位于[,]第二个的等级即可
            return  -1     //返回，a排列在b之前
        } else {
            return  1      //返回，b排列在a之前
        }
    });
    return  mac2bind.map(one=>one[0]);
}


// type EqpSort = "21" | "22" | "41" | "42" | "43";
//type SupportedMenuLinkComponent = object | keyof JSX.IntrinsicElements;
// type RepTypeConfig = {
//     gray: EqpSort;
// };

/** 具体配置：需要考虑到逻辑上的包含关系，避免有冗余配置项。
 五个选择项，全部都得填充。二维数组形式的，内层数组5项目 按顺序如下:
 第1个 EQP_SORT" "设备种类"   若==''表示不关心设备品种，都能用。(适应性？第一个配置若只有一个字符？或者也用数组可配呢？)
 第2个 EQP_VART" "设备品种"   若==''表示不关心设备品种，都能用。
 第3个 SUB_EQP_VART"  "子设备品种",   若==''表示不关心子设备品种，都能用。
 第4个 的"OPE_TYPE", "业务类型",  必须选定一个特定的类型！ 单票否决的：业务类型必须完全一致，业务类型也不可省略。null=兼容都可；多选是[]数组形式的。
 第5个 字段 参数： #必须委托的?，【最后一个参数】要=false才是法定的才能用的， true=委托的才能用的，若填上==null=兼容都可用。
 ['41','413','9999','REGUL',null] , 不限制设备类型['','','','REGUL',false]
 $ 使用场景：是否属于主报告的报告模板类型,可以当做主报告使用，只能用于分项报告情况。 独立主报告，分项报告，主报告必须融合分项报告，分项报告必须依附主报告。
 可以当成分项还是可以当成主报告来做的？审核人可以检查的吧。没有必要在这里配置选择项的？。
 todo://类型指代能力不强；？所有承压类的？
 ？还不能指定水质"Z"的匹配。
 * */

const ModelMapConfig = {
    "EL-DJ": [
        ['41','413','9999','REGUL',null], ['','','','REGUL',false]
    ],
    "EL-JJ": [
        ['31','311','','INSTA',false], ['31','','','INSTA',null]
    ],
    "SAFT-EL": [
        ['31','311','','ESTIMATE',null],
    ],
    "WALK-SAF": [
        ['33','','','ESTIMATE',null],
    ],
    "EL_SSAF": [
        ['31','','','ESTIMATE',true],
    ],
    "WALK_SSAF": [
        ['33','331','','ESTIMATE',true],
    ],
    "ESCL-DJ": [
        ['33','331','','REGUL',null],
    ],
    "WALK-JJ": [
        ['33','331','',['INSTA','REPAIR'],null],
    ],
    "ROL-DJ": [
        ['31','311','3002','REGUL',null], ['','','','REGUL',false]
    ],
    "ROL-JJ": [
        ['31','311','3002','INSTA',null],
    ],
    "SUNDR-JJ": [
        ['34','343','',null,null],
    ],
    "SUNDR-DJ": [
        ['34','343','','REGUL',null],
    ],
    "SUNDR_WDJ": [
        ['34','343','','REGUL',true],
    ],
    "HYDLIC-DJ": [
        ['32','','','REGUL',null],
    ],
    "HYDLIC_JJ": [
        ['32','','',['INSTA','REPAIR','REFORM'],null],
    ],
    "EL-WT": [
        ['31','','','REGUL',false],
    ],
    "EL-WTJJ": [
        ['31','','',['INSTA','REPAIR','REFORM'],true],
    ],
    'ELV-TS': [
        ['31','','','TEST',null],
    ],
    'WALK-TS': [
        ['33','','','TEST',null],
    ],
    'SUNDRI_TS': [
        ['34','343','','TEST',null],
    ],
    "VS-DJ": [
        ['21','','','REGUL',false], ['','','','REGUL',false]
    ],
    "VS-WD": [
        ['21','','','REGUL',true]
    ],
    "VS_WNJ": [
        ['21','','','ANNUAL',true]
    ],
    "VS-NJ": [
        ['21','','',null,null]
    ],
    "IMCONT-SA": [
        ['21','','','SAFETYINS',null]
    ],
    "VS-ZJ": [
        ['','','','MANUFACT',false]
    ],
    "VS-RJJ": [
        ['21','','',['REPAIR','REFORM'],null]
    ],
    "VS-BZJ": [
        ['','','','MANUFACT',false]
    ],
    "ASEMBWE_AJ": [
        ['21','','','INSTA',null]
    ],
    "SPHERIC_AJ": [
        ['21','','','INSTA',null]
    ],
    "OXYGENC_AJ": [
        ['24','','','INSTA',null]
    ],
    "CYLIND-ZJ": [
        ['23','','','MANUFACT',null]
    ],
    "COMPLTVS_WJ": [
        ['21','','','INSTA',true]
    ],
    "MVS-QJ": [
        ['22','','','REGUL',null]
    ],
    "MVS-NJ": [
        ['22','','','ANNUAL',null]
    ],
    "SPHERIC-DJ": [
        ['21','','2002','REGUL',null]
    ],
    "OXYGEN-WNJ": [
        ['24','','','ANNUAL',true]
    ],
    "OXYGEN-DJ": [
        ['24','','','REGUL',null]
    ],
    "STATIONU_DJ": [
        ['21','','','REGUL',null]
    ],
    "SKIDMNT_ZJ": [
        ['','','','MANUFACT',null]
    ],
    "TANKER-NJ": [
        ['R3','','','ANNUAL',null]
    ],
    'THICKM_VS': [
        ['41','413','','REGUL',false], ['41','413','9999','REGUL',true]
    ],
    'THICK_MS': [
        ['83','','','REGUL',null]
    ],
    'SONIC_TS': [
        ['83','','','REGUL',null]
    ],
    'SPECTR_AL': [
        ['83','','','REGUL',null]
    ],
    'TOFD_TS': [
        ['41','413','','REGUL',false], ['41','413','9999','REGUL',true]
    ],
    "CR-JJ": [
        ['41','413','','INSTA',false], ['','','','INSTA',true]
    ],
    "CR-JJWT": [
        ['41','','',['INSTA','REPAIR','REFORM'],true], ['42','','',['INSTA','REPAIR','REFORM'],true]
    ],
    "CR-INWT": [
        ['41','','','FIRST',true],['42','','','FIRST',true]
    ],
    "CR-DJ": [
        ['41','','','REGUL',null],['42','','','REGUL',null]
    ],
    "SINGB-IN": [
        ['41','419','','FIRST',null]
    ],
    "PARK-JJ": [
        ['4D','4D1','','INSTA',null]
    ],
    "PARK-DJ": [
        ['4D','4D1','','REGUL',null]
    ],
    "MOBCR-IN": [
        ['44','','','FIRST',false]
    ],
    "MOBCR_WIN": [
        ['44','','','FIRST',true]
    ],
    "GANTR-DJ": [
        ['47','','','REGUL',null]
    ],
    "GANTR-JJ": [
        ['47','','',['INSTA','REPAIR','REFORM'],null]
    ],
    "TOWER-JJ": [
        ['43','','','INSTA',null]
    ],
    "TOWER-DJ": [
        ['43','','','REGUL',null]
    ],
    "BRIERECT_JJ": [
        ['42','429','',['INSTA','REPAIR','REFORM'],null]
    ],
    "BRIERECT_DJ": [
        ['42','429','','REGUL',null]
    ],
    "CONSTRU-JJ": [
        ['48','486','',['INSTA','REPAIR','REFORM'],null]
    ],
    "CONSTRU-DJ": [
        ['48','486','','REGUL',null]
    ],
    "LIFT-DJ": [
        ['48','487','','REGUL',null],
    ],
    "LIFT-JJ": [
        ['48','487','',['INSTA','REPAIR','REFORM'],null]
    ],
    "CR-SMMS": [
        ['41','','','OTHER',null],['42','','','OTHER',null],
    ],
    "FORK-DJ": [
        ['51','511','','REGUL',null], ['','','','REGUL',false]
    ],
    "TOUR-IN": [
        ['52','','','REGUL',null], ['','','','FIRST',null]
    ],
    "TOUR-INW": [
        ['52','','','REGUL',true], ['','','','FIRST',true]
    ],
    "FORK_WIN": [
        ['51','511','','FIRST',true],
    ],
    "FORK-WTJ": [
        ['51','511','','REGUL',true],
    ],
    "BALANCE_TT": [
        ['51','','','TYPETST',null],
    ],
    "VALV-OF": [
        ['','','','OTHER',false]
    ],
    "VALV-ON": [
        ['','','','OTHER',false]
    ],
    "PRESBEAR-ZJ": [
        ['','','','MANUFACT',null]
    ],
    "INDPL-DJ": [
        ['83','831','','REGUL',null]
    ],
    "INDPL-NJ": [
        ['83','831','',null,null]
    ],
    "INDPL-JJ": [
        ['83','831','','INSTA',null]
    ],
    "PGAS-JJ": [
        ['82','821','','INSTA',null]
    ],
    "PLASTI-QJ": [
        ['82','821','','REGUL',null]
    ],
    "STEEL_DJ": [
        ['82','','','REGUL',null],['83','','','REGUL',null],
    ],
    "STEELT_DJ": [
        ['82','','','REGUL',null],['83','','','REGUL',null],
    ],
    "STEELF_DJ": [
        ['82','','','REGUL',null],['83','','','REGUL',null],
    ],
    "HEATING_JJ": [
        ['82','822','',['INSTA','REFORM','REPAIR'],null],
    ],
    "LDISTAN-JJ": [
        ['81','','',null,null],
    ],
    "LDISTAN-DJ": [
        ['81','','','REGUL',null],
    ],
    "LDISTAN-NJ": [
        ['81','','','ANNUAL',null],
    ],
    "UTILITY-NJ": [
        ['82','','','ANNUAL',null],
    ],
    "POLYETH_ZJ": [
        ['71','','','MANUFACT',null],
    ],
    "ASSEMBLY_ZJ": [
        ['72','','','MANUFACT',null],
    ],
    "ARCWELD_ZJ": [
        ['71','','','MANUFACT',null],
    ],
    "BOIL-NJ": [
        ['11','','','REGUL',null]
    ],
    "BOIL-WB": [
        ['11','','','ANNUAL',null]
    ],
    "ORGAN-NJ": [
        ['13','','', 'REGUL',null]
    ],
    "ORGAN-WB": [
        ['13','','', 'ANNUAL',null]
    ],
    "BOIL-SA": [
        ['11','','','MANUFACT',null]
    ],
    "BOIL-JJ": [
        ['11','','','INSTA',null]
    ],
    "ASSEMBL-JJ": [
        ['11','','','INSTA',null],['12','','','INSTA',null],
    ],
    "BULKIND_AJ": [
        ['11','','','INSTA',null],['12','','','INSTA',null],
    ],
    "BOIL-RJ": [
        ['11','','',['REFORM','REPAIR'],null]
    ],
    "POWER-IN": [
        ['11','111','1002','REGUL',null]
    ],
    "POWER-WB": [
        ['11','111','1002','ANNUAL',null]
    ],
    "POWER-RJJ": [
        ['11','111','1002',['REFORM','REPAIR'],null]
    ],
    "POWER_AJ": [
        ['11','111','1002','INSTA',null],
    ],
    "THMEFF-TS": [
        ['12','121','1003','THERMAL',null]
    ],
    "THMEFF-WT": [
        ['','','','THERMAL',true]
    ],
    "THERMAL_DT": [
        ['','','','THERMAL',null]
    ],
    "THERMAL_WDT": [
        ['','','','THERMAL',true]
    ],
    "BPERFORM_TS": [
        ['11','111','1002','EXPERIMENT',null]
    ],
    "OBSERV-JJ": [
        ['61','','',['INSTA','REPAIR'],null],
    ],
    "OBSERV-DJ": [
        ['61','611','','REGUL',null],
    ],
    "WATER_DJ": [
        ['6D','','','REGUL',null],
    ],
    "WATER_JJ": [
        ['6D','','',['INSTA','REPAIR','REFORM'],null],
    ],
    "FLIGHT-DJ": [
        ['65','','','REGUL',null],
    ],
    "SLIDING_DJ": [
        ['62','','','REGUL',null],
    ],
    "SLIDING_JJ": [
        ['62','','',['INSTA','REPAIR','REFORM'],null],
    ],
    "OVEHEAD-DJ": [
        ['63','','','REGUL',null],
    ],
    "AIRCRAF_DJ": [
        ['67','','','REGUL',null],
    ],
    "AIRCRAF_JJ": [
        ['67','','',['INSTA','REPAIR','REFORM'],null],
    ],
    "DODGEM-DJ": [
        ['6A','','','REGUL',null],
    ],
    "ZIPLINE-DJ": [
        ['6B','','','REGUL',null],
    ],
    "WATERBO_TS": [
        ['','','1003','TEST',null],
    ],
    "POWERSTM_TS": [
        ['','','1002','TEST',null],
    ],
    "ORGANICHT_TS": [
        ['13','','','EXPERIMENT',null],['','','','EXPERIMENT',null],
    ],
    "ORGANICHT_NT": [
        ['13','','','EXPERIMENT',null],['','','','EXPERIMENT',null],
    ],
    "WATERBO_WTS": [
        ['','','1003','TEST',true],
    ],
    "STARTUPST_TS": [
        ['','','','TEST',null],
    ],
}
